package com.event.web.controller.system;

import com.event.common.annotation.Log;
import com.event.common.core.controller.BaseController;
import com.event.common.core.domain.AjaxResult;
import com.event.common.core.page.TableDataInfo;
import com.event.common.enums.BusinessType;
import com.event.system.domain.SysEvent;
import com.event.system.domain.SysEventOrder;
import com.event.system.domain.SysEventRegion;
import com.event.system.service.ISysEventOrderService;
import com.event.system.service.ISysEventService;
import com.event.system.service.ISysEventSortService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/system/event")
public class SysEventController extends BaseController {

    private String prefix = "system/event";

    @Autowired
    private ISysEventService service;

    @Autowired
    private ISysEventSortService sysEventSortService;

    @Autowired
    private ISysEventOrderService sysEventOrderService;

    @RequiresPermissions("system:event:view")
    @GetMapping()
    public String event(ModelMap mmap)
    {
        mmap.put("eventSort", sysEventSortService.selectEventSortAll());
        return prefix + "/event";
    }

    @RequiresPermissions("system:event:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysEvent sysEvent)
    {
        startPage();
        List<SysEvent> list = service.selectSysEventList(sysEvent);
        return getDataTable(list);
    }

    /**
     * 展会区域摊位申请
     */
    @RequiresPermissions("system:event:edit")
    @Log(title = "展会区域申请", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated SysEventOrder sysEventOrder)
    {
        Long userId = getUserId();
        sysEventOrder.setUserId(userId);
        sysEventOrder.setOrderStatus(1);
        sysEventOrder.setOrderRemarks("首页申请");
        return toAjax(sysEventOrderService.add(sysEventOrder));
    }

    @RequiresPermissions("system:event:myList")
    @PostMapping("/myList")
    @ResponseBody
    public TableDataInfo myList(SysEvent sysEvent)
    {
        startPage();
        Long userId = getUserId();
        sysEvent.setUserId(userId);
        List<SysEvent> list = service.selectSysEventByList(sysEvent);
        return getDataTable(list);
    }

    /**
     * 新增展会区域
     */
    @GetMapping("/myList")
    public String add(ModelMap mmap)
    {
        mmap.put("eventSort", sysEventSortService.selectEventSortAll());
        return prefix + "/myList";
    }
}
